#include <bits/stdc++.h>
using namespace std;

int n, q, ans;
bool t[1505][1505];
int to[1505][1505];

string s;

void init(int x, int y)
{
    if (to[x][y] != 0 || x > n || y > n)
        return;
    if (t[x][y])
        init(x, y + 1), to[x][y] = to[x][y + 1];
    else
        init(x + 1, y), to[x][y] = to[x + 1][y];
}

void update(int x, int y)
{
    if (x < 1 || y < 1)
        return;
    if (t[x][y])
        ans += to[x][y + 1] - to[x][y], to[x][y] = to[x][y + 1];
    else
        ans += to[x + 1][y] - to[x][y], to[x][y] = to[x + 1][y];
    if (t[x][y - 1])
        update(x, y - 1);
    if (!t[x - 1][y])
        update(x - 1, y);
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s >> to[i][n + 1];
        for (int j = 0; j < n; j++)
            if (s[j] == 'R')
                t[i][j + 1] = 1;
    }
    for (int i = 1; i <= n; i++)
        cin >> to[n + 1][i];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            init(i, j), ans += to[i][j];
    cin >> q;
    cout << ans << endl;
    for (int i = 1; i <= q; i++) {
        int x, y;
        cin >> x >> y;
        t[x][y] = !t[x][y];
        update(x, y);
        cout << ans << endl;
    }
    return 0;
}